package com.example.demo.controller;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自定义监控指标
 * http://localhost:8889/actuator/metrics/demo.meter.test
 *
 *
 */
@RestController
@RequestMapping("/meter")
public class MeterRegistrtyController implements InitializingBean {
    @Autowired
    MeterRegistry registry;
    Counter counter;

    @Override
    public void afterPropertiesSet() throws Exception {
        counter = registry.counter("demo.meter.test");
    }

    @RequestMapping("/test")
    public String test() {

        counter.increment();
        return "OK";
    }
}
